package com.betterjr.modules.risk.loan.data;

import java.util.List;

import com.betterjr.common.utils.Collections3;
import com.betterjr.modules.customer.entity.CustMechBankAccount;
import com.betterjr.modules.risk.loan.dao.FillBankAbstract;
import com.betterjr.modules.risk.loan.entity.LoanProjectBank;
import com.betterjr.modules.risk.loan.entity.LoanProjectRelation;

public class CustWithHoldPrinpalFillBank extends FillBankAbstract {

    private String flag = LoanProjectBankConstantCollections.LOANBANK_TYPE_CUSTWITHHOLDPRINIPALBANK;

    @Override
    public boolean fillBank(LoanProjectRelation anLoan, LoanProjectBank anBank) {
        if (anLoan != null && anBank != null && flag.equals(anBank.getType())) {
            anLoan.setCustWithHoldPrincipalBank(anBank);
            anLoan.setCustWithHoldPrincipalBankIds(anBank.getBankId() + "");
            return true;
        }
        return false;
    }

    @Override
    public void fillBank(LoanProjectRelation anLoan, List<CustMechBankAccount> accountList) {

        // 供应商 扣账帐号本金
        List<CustMechBankAccount> custAccountBanks = getBankAccount(accountList,
                anLoan.getCustWithHoldPrincipalBankIds());
        if (!Collections3.isEmpty(custAccountBanks)) {
            anLoan.setCustWithHoldPrincipalBank(LoanProjectBank.createBank(
                    LoanProjectBankConstantCollections.LOANBANK_TYPE_CUSTWITHHOLDPRINIPALBANK,
                    Collections3.getFirst(custAccountBanks), anLoan.getId()));
        }

    }

}
